package com.itlong.cloud.sdkv3;

import com.alibaba.fastjson.JSONObject;
import com.itlong.cloud.sdkv3.service.ITaskService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
import java.util.TreeMap;

//@EnableScheduling
//@RestController
public class TestTask {

    private static Logger LOG = LoggerFactory.getLogger(TestTask.class);

    private final String robotId = "000001268218";

    private String last = "";

    @Autowired
    ITaskService iTaskService;

    @Scheduled(fixedRate = 1000)
    public void t01() {
        try {
            Map<Object, Object> map = iTaskService.getTaskData(robotId);
            TreeMap<Object, Object> t = new TreeMap<>();
            for (Map.Entry<Object, Object> entry : map.entrySet()) {
                String mapKey = entry.getKey().toString();
                String mapValue = entry.getValue().toString();
                t.put(mapKey, mapValue);
            }
            String content = JSONObject.toJSONString(t);
            if (!content.equals(last)) {
                last = content;
                LOG.info("【sdkv3任务变化情况】{}", content);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}